#!/bin/bash

CHAPTER=${1%/}

cp $CHAPTER/index.md $CHAPTER/pdf.md

for ly in $(ls $CHAPTER/*.ly); do
	name=$(basename $ly .ly)
	sed -e "s|@$name|\\\\lilypondfile[]\{$CHAPTER/$name.ly\}|g" -i $CHAPTER/pdf.md
done;


pandoc $CHAPTER/pdf.md --include-in-header=include/preamble --latex-engine=lualatex --latex-engine-opt=-shell-escape -o output/$CHAPTER.pdf

rm -rf tmp-ly/
rm $CHAPTER/pdf.md
